package com.hzgj.bcl.soa.interceptor;

import com.hzgj.bcl.soa.Event;
import com.hzgj.bcl.soa.Interceptor;
import com.hzgj.bcl.soa.rpc.message.Message;

/**
 * Created by dell on 2015/3/31.
 */
public class CollectBytesInterceptor extends Interceptor {

    protected long sent_msgs = 0, received_msgs = 0, sent_bytes = 0, received_bytes = 0;

    @Override
    public Object up(Event evt) {
        switch (evt.getType()) {
            case Event.MSG:
                Message msg = (Message) evt.getArg();
                received_msgs++;
                received_bytes += msg.getLength();
                break;
        }
        return up_int.up(evt);
    }


    @Override
    public Object down(Event evt) {
        if (evt == null) {
            return null;
        }
        if (evt.getType() == Event.MSG) {
            sent_msgs++;
            sent_bytes += ((Message) evt.getArg()).getLength();
        }
        return down_int.down(evt);
    }
}
